/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package chuiniurobot.message;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.Map;
import org.apache.mina.core.session.IoSession;

/**
 *服务器返回对战响应消息
 * @author zhengji
 */
public class ResponsePKMessage extends BaseMessage{

    int vsPlayerId;
    public ResponsePKMessage(IoSession ioSession, String requestJSONStr) {
        super(ioSession, requestJSONStr);
    }

    @Override
    public void execute() {
        JSONObject jsonObj=JSON.parseObject(this.requestJSONStr);
        
        int code=jsonObj.getIntValue("c");
        
        this.vsPlayerId =jsonObj.getIntValue("vsid");
        if(code== BaseMessage.SUCCESS){
            //发送准备开始消息
            this.sendReadyPlayMessage();
        }
     }
    
     private void sendReadyPlayMessage() {
        
        this.setVSPlayerId(this.vsPlayerId);
        
        int playerId=this.getPlayerId();
        
        
        Map<String,String> map=new HashMap<String,String>();
        
        map.put("cmd", BaseMessage.ReadyPlayCommand);
        map.put("id", String.valueOf(playerId));
        map.put("vsid", String.valueOf(this.vsPlayerId));
        
        this.sendMessage(map);
         
    }
    
}
